package com.xwh.shop.user.service.controller;

import com.xwh.shop.common.Result;
import com.xwh.shop.user.model.dto.MemberLoginDTO;
import com.xwh.shop.user.model.vo.MemberLoginVO;
import com.xwh.shop.user.service.service.MemberService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xwh
 * @since 2025-07-15
 */
@Tag(name = "会员管理")
@RestController
@RequestMapping("/member")
public class MemberController {
    @Resource
    private MemberService memberService;

    @PostMapping
    public Result<MemberLoginVO> login(@RequestBody MemberLoginDTO memberLoginDTO){
        MemberLoginVO loginVO = memberService.login(memberLoginDTO);
        return Result.success(loginVO);
    }


    @Operation(summary = "重置密码",description = "重置会员密码")
    @PutMapping("resetPassword/{id}")
    public Result<Object> resetPassword(@PathVariable Long id){
        this.memberService.resetPassword(id);
        return Result.success();
    }

    @Operation(summary = "启用禁用会员", description = "根据ID启用或禁用会员")
    @PutMapping("enable/{id}")
    public Result<Object> enable(@PathVariable Long id) {
        this.memberService.enable(id);
        return Result.success();
    }

    @GetMapping("/getMemberIdByToken")
    public Result<Long> getMemberIdByToken(){
        Long id = this.memberService.getMemberIdByToken();
        return Result.success(id);
    }
}
